package cn.edu.ctgu;


public class YesterDate {
    public static String yesterDate(int year, int month, int day) {
        if (day > 1) {
            day--;
        } else {
            month--;
            if (month == 0) {
                month = 12;
                year--;
            }
            day = getLastMonthDays(year, month);
        }
        return String.format("%d-%02d-%02d", year, month, day);
    }

    private static int getLastMonthDays(int year, int month) {
        switch (month) {
            case 4:
            case 6:
            case 9:
            case 11:
                return 30;
            case 2:
                if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
                    return 29;
                } else {
                    return 28;
                }
            default:
                return 31;
        }
    }
}
